package com.bocai.controller;

import com.bocai.bean.CustomEvent;
import com.bocai.service.ICustomEventService;
import com.bocai.utils.CodeEnum;
import com.bocai.utils.DateUtils;
import com.bocai.utils.ObjUtils;
import com.bocai.utils.ResponseData;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

@Controller
@RequestMapping("customEvent")
public class CustomEventConttoller {

    @Autowired
    private ICustomEventService customEventService;

    @ApiOperation(value = "批量设置比赛", notes = "热门，玩法，禁用")
    @RequestMapping(value = "/setEvents", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "eventList", dataType = "json string", value = "比赛信息", defaultValue = ""),
    })

    @ResponseBody
    public ResponseData setEvents(String eventList) {

        ResponseData data = new ResponseData();

        JSONArray jsonArray = JSONArray.fromObject(eventList);

        return customEventService.setEvents(jsonArray,data);
    }


    @ApiOperation(value = "设置比赛", notes = "热门，玩法，禁用")
    @RequestMapping(value = "/setEvent", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "eventId", dataType = "integer", value = "比赛id", defaultValue = ""),
            @ApiImplicitParam(paramType = "query", name = "isHot", dataType = "integer", value = "0不是热门，1：热门", defaultValue = ""),
            @ApiImplicitParam(paramType = "query", name = "isEnable", dataType = "integer", value = "是否禁用0:没有禁用，1禁用", defaultValue = ""),
            @ApiImplicitParam(paramType = "query", name = "ruleTypes", dataType = "string", value = "玩法传0为开通所有玩法", defaultValue = "0"),
            @ApiImplicitParam(paramType = "query", name = "homeName", dataType = "string", value = "主队名称", defaultValue = "0"),
            @ApiImplicitParam(paramType = "query", name = "awayName", dataType = "string", value = "客队名称", defaultValue = "0"),
            @ApiImplicitParam(paramType = "query", name = "eventTime", dataType = "string", value = "开赛时间yyyy-MM-dd HH:mm:ss", defaultValue = "0"),
    })

    @ResponseBody
    public ResponseData setEvent(Integer eventId,
                                 Integer isHot,
                                 Integer isEnable,
                                 String ruleTypes,
                                 String homeName,
                                 String awayName,
                                 String eventTime) {

        ResponseData data = new ResponseData();


        return this.customEventService.setEvent(eventId,isHot,isEnable,ruleTypes,homeName,awayName,eventTime,data);

    }


    @ApiOperation(value = "查询热门禁用比赛", notes = "查询热门禁用比赛列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "isEnable", required = false, dataType = "int", value = "是否禁用（0不禁用1禁用）", defaultValue = "0"),
            @ApiImplicitParam(paramType = "query", name = "isHot", required = false, dataType = "int", value = "是否热门（0不热门 1热门）", defaultValue = "0"),
    })
    @RequestMapping(value = "/getHotEvents", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData getHotEvents(Integer isEnable, Integer isHot) {
        ResponseData data = new ResponseData();
        CustomEvent customEvent = new CustomEvent();
        if (isEnable != null)
            customEvent.setIsEnable(isEnable);
        if (isHot != null)
            customEvent.setIsHot(isHot);
        data.setResults(customEventService.selectEvents(customEvent));
        return data;
    }

    @ApiOperation(value = "查询自定义比赛详情", notes = "查询自定义比赛")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "eventId", required = false, dataType = "int", defaultValue = "0"),
    })
    @RequestMapping(value = "/getCustomEvents", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData getHotEvents(Integer eventId) {
        ResponseData data = new ResponseData();

        CodeEnum codeEnum = ObjUtils.validateParams(new Object[]{eventId});
        if (ObjUtils.isNotEmpty(codeEnum)) {
            data.setCodeEnum(CodeEnum.CODE_90002);
            return data;
        }

        data.setCodeEnum(CodeEnum.SUCCESS);

        data.setResults(customEventService.selectEvent(eventId));
        return data;
    }
}
